package com.zsc.koail.camerarecorder.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zsc.koail.camerarecorder.R;
import com.zsc.koail.camerarecorder.bean.VideoBean;

import java.util.List;

/**
 * @author zsc
 * @create 2018/8/6 0006
 * @Describe
 */
public class VideoAdapter extends BaseAdapter {
    private List<VideoBean> mVideoBeanList;

    public VideoAdapter(List<VideoBean> videoBeanList) {
        mVideoBeanList = videoBeanList;
    }

    @Override
    public int getCount() {
        return mVideoBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return mVideoBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_video, parent, false);
            viewHolder.mImageView = convertView.findViewById(R.id.img);
            viewHolder.mTextView = convertView.findViewById(R.id.name);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.mImageView.setImageBitmap(mVideoBeanList.get(position).getBitmap());
        viewHolder.mTextView.setText(mVideoBeanList.get(position).getName());
        return convertView;
    }

    public void notifyVideo(List<VideoBean> videoBeanList) {
        this.mVideoBeanList = videoBeanList;
        notifyDataSetChanged();
    }

    public VideoBean getVideo(int position) {
        return mVideoBeanList.get(position);
    }


    private static class ViewHolder {
        public TextView mTextView;
        public ImageView mImageView;
    }
}
